import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/recovery_controller.dart';
import '../widgets/auth_header.dart';
import '../../shared/widgets/forms/app_text_field.dart';
import '../../shared/widgets/buttons/app_button.dart';

/// 恢复密码视图
class RecoveryView extends GetView<RecoveryController> {
  const RecoveryView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('找回密码'),
        elevation: 0,
        backgroundColor: Colors.transparent,
      ),
      body: SafeArea(
        child: SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 16.0),
          child: Form(
            key: controller.formKey,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                // 头部
                const AuthHeader(
                  title: '忘记密码了?',
                  subtitle: '输入您的邮箱地址，我们将发送密码重置链接给您。',
                ),
                
                const SizedBox(height: 40),
                
                // 邮箱输入框
                AppTextField(
                  controller: controller.emailController,
                  labelText: '邮箱',
                  hintText: '请输入您注册时使用的邮箱地址',
                  keyboardType: TextInputType.emailAddress,
                  prefixIcon: const Icon(Icons.email_outlined),
                  validator: controller.validateEmail,
                ),
                
                const SizedBox(height: 30),
                
                // 发送重置邮件按钮
                Obx(() => AppButton(
                  text: '发送重置链接',
                  onPressed: controller.sendPasswordResetEmail,
                  isLoading: controller.isLoading.value,
                  isEnabled: !controller.isEmailSent.value, // 发送后禁用按钮
                )),
                
                const SizedBox(height: 20),
                
                // 提示信息
                Obx(() => controller.isEmailSent.value
                    ? const Text(
                        '密码重置链接已发送到您的邮箱，请注意查收。如果未收到，请检查垃圾邮件或稍后重试。',
                        textAlign: TextAlign.center,
                        style: TextStyle(color: Colors.green, fontSize: 14),
                      )
                    : const SizedBox.shrink()),
                
                const SizedBox(height: 30),
                
                // 返回登录链接
                Center(
                  child: TextButton(
                    onPressed: controller.navigateToLogin,
                    child: const Text('返回登录'),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
} 